package com.hd.service.activiti.impl;

import com.hd.dao.BaseDao;
import com.hd.entity.activiti.DeploymentEntity;
import com.hd.service.activiti.DeploymentEntityService;
import com.hd.util.StringUtils;
import com.hd.util.result.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author: hzhh123
 * @Date: 2018/12/13 20:59
 */
@Service("deploymentEnityService")
public class DeploymentEntityServiceImpl implements DeploymentEntityService {
    @Autowired
    private BaseDao<DeploymentEntity,String>deploymentEntityDao;
    @Override
    public void save(DeploymentEntity deploymentEntity) {
        deploymentEntity.setStatus(1);
        deploymentEntity.setCreateTime(new Date());
        deploymentEntityDao.save(deploymentEntity);
    }

    @Override
    public void cancel(String id) {
        String hql="update DeploymentEntity set status=0 where id=?";
        deploymentEntityDao.execute(hql,id);
    }

    @Override
    public void selectDataGrid(PageInfo info) {
        Map<String,Object> condition=info.getCondition();
        List<Object> params=new ArrayList<>();
        String hql="from DeploymentEntity where status=1 ";
        if(StringUtils.isNotNull(condition.get("name"))){
            hql+=" and name like ?";
            params.add("%"+condition.get("name")+"%");
        }
        hql+=" order by createTime asc";
        String countSql="select count(*) "+hql;
        Long total=deploymentEntityDao.getCountByList(countSql,params);
        List<DeploymentEntity>deploymentEntities=deploymentEntityDao.findPage(hql,info.getNowpage(),info.getPagesize(),params);
        info.setTotal(Integer.parseInt(""+total));
        info.setRows(deploymentEntities);
    }
}

